﻿package cz.dadul.adventure.asset {
    
    import flash.display.MovieClip;
    
    /**
     * MovieClip class that adds an isPlaying property
     * to indicate whether or not the movie clip is 
     * currently playing.  Have your classes extend this
     * class instead of MovieClip or set this class as the
     * Base class of your movie clip(s) in the library to
     * have those instances gain the isPlaying property.
     */
    public class MovieClipWithIsPlaying extends MovieClip {
        
        /**
         * Private property to internally keep track of whether or
         * not the current movie clip is being played
         */
        private var _isPlaying:Boolean = true;
            
        /**
         * Getter function creating a public, read-only isPlaying
         * property allowing users to get but not set the _isPlaying
         *  property to determine if the movie clip is playing
         */
        public function get isPlaying():Boolean {
            return _isPlaying;
        }
        
        /** 
         * Constructor
         */
        public function MovieClipWithIsPlaying(){
            super();
        }
        
        // override all timeline commands for movie clip that would
        // affect the isPlaying property of the movie clip:
        
        public override function gotoAndPlay(frame:Object, scene:String = null):void {
            _isPlaying = true;
            super.gotoAndPlay(frame, scene);
        }
        
        public override function gotoAndStop(frame:Object, scene:String = null):void {
            _isPlaying = false;
            super.gotoAndStop(frame, scene);
        }
        
        public override function nextFrame():void {
            _isPlaying = false;
            super.nextFrame();
        }
        
        public override function nextScene():void {
            _isPlaying = true;
            super.nextScene();
        }
        
        public override function play():void {
            _isPlaying = true;
            super.play();
        }
        
        public override function prevFrame():void {
            _isPlaying = false;
            super.prevFrame();
        }
        
        public override function prevScene():void {
            _isPlaying = true;
            super.prevScene();
        }
        
        public override function stop():void {
            _isPlaying = false;
            super.stop();
        }
    }
}